package com.joysuch.wwyt.screen.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.exception.ApiCoreException;
import com.joysuch.wwyt.screen.entity.ScreenMapPerspective;
import com.joysuch.wwyt.screen.service.ScreenMapPerspectiveService;
import com.joysuch.wwyt.screen.vo.ScreenMapPerspectiveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jwk
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/wwyt/screen-map-perspective")
@Api(tags = "大屏视角配置")
public class ScreenMapPerspectiveController {


    @Autowired
    private ScreenMapPerspectiveService screenMapPerspectiveService;

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "保存或修改")
    @RequiresPermissions("wwyt:map-perspective:save")
    public ResultBean saveOrUpdate(@RequestBody ScreenMapPerspective screenMapPerspective) {
        try {
            screenMapPerspectiveService.saveMapPerspective(screenMapPerspective);
            return ResultBean.defaultSuccessResult();
        } catch (ApiCoreException e) {
            return ResultBean.fail(e.getCode(), e.getMessage());
        }
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    @RequiresPermissions("wwyt:map-perspective:delete")
    public ResultBean delete(Long perspectiveId) {
        ScreenMapPerspective perspective = new ScreenMapPerspective();
        perspective.setDeleteFlag("1");
        perspective.setId(perspectiveId);
        screenMapPerspectiveService.updateById(perspective);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("/list")
    @ApiOperation(value = "视角配置列表")
    public ResultBean list() {
        List<ScreenMapPerspectiveVO> list = screenMapPerspectiveService.findList();
        return ResultBean.success(list);
    }

    @GetMapping("/getPerspectiveByCurUser")
    @ApiOperation(value = "当前用户的视角配置")
    public ResultBean getPerspectiveByCurUser() {
        ScreenMapPerspective perspective = screenMapPerspectiveService.getPerspectiveByCurUser();
        return ResultBean.success(perspective);
    }
}

